<template>
	<view class="view">
		<view class="login">
			<text>登陆</text>
		</view>
		<view style="margin-top: 10%;">
			<uni-forms ref="form" >
				<uni-forms-item label="账号" name="">
					<uni-easyinput  v-model="user.userAccount" placeholder="请输入账号" />
				</uni-forms-item>
				<uni-forms-item label="密码" name="">
					<uni-easyinput  v-model="user.userPassword" placeholder="请输入密码"  type="password"/>
				</uni-forms-item>
				<uni-forms-item label="" name="">
					<view style="margin: 0px 5%; display: flex;justify-content: space-between;align-items: center;">
						<text style="border-bottom: 1px solid #ADD8E6;" @click="register">注册</text>
						<text style="border-bottom: 1px solid #ADD8E6;" @click="retrieve">找回密码</text>
					</view>
				</uni-forms-item>
				<uni-forms-item label="" name="">
					<button type="primary" @click="loginto">登陆</button>
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:{
					userAccount:"",
					userPassword:""
				},
				login:{}
			}
		},
		methods: {
			register(){
				uni.navigateTo({
					url: '/pages/register/register',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			retrieve(){
				uni.navigateTo({
					url: '/pages/retrieve/retrieve',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			loginto(){
				uni.request({
					url: this.api.login,
					method: 'POST',
					data: this.user,
					success: res => {
						if(res.data.code==200){
							this.login=res.data.obj
							this.login.userImage="http://127.0.0.1:8989/"+this.login.userImage
							uni.setStorageSync('token',this.login)
							uni.reLaunch({
								url:'/pages/personal/personal'
							})
						}
						else{
							uni.showToast({
								title: res.data.message,
								icon:'error'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>
	page,
	.view {
		width: 100%;
		height: 100%;
		// background-color:#D3D3D3 ;
	}
.login{
	margin-left: 10%;
	margin-top: 10%;
	font-size: 24px;
	font-weight: bold;
}
</style>
